﻿Imports ajayumi.develop.win32.WebResourcesCatcher.Service
Imports System.Threading

Public Class FrmMainBase
    Implements IMainFormBase

#Region "IMainBase"

    Public Sub AddTabPage(tp As System.Windows.Forms.TabPage) Implements Service.IMainFormBase.AddTabPage
        Me.TabControl1.TabPages.Add(tp)
    End Sub

    Public Sub RemoveTabPage(tp As System.Windows.Forms.TabPage) Implements Service.IMainFormBase.RemoveTabPage
        Me.TabControl1.TabPages.Remove(tp)
    End Sub

#End Region


    Protected Overrides Sub OnLoad(e As System.EventArgs)
        MyBase.OnLoad(e)

        AddHandler Application.ThreadException, Sub(sender As Object, evt As ThreadExceptionEventArgs)
                                                    Console.ForegroundColor = ConsoleColor.Red
                                                    Console.WriteLine("程序发生异常：{0}", vbCrLf & evt.Exception.Message)
                                                    Console.ForegroundColor = ConsoleColor.White
                                                    WebResourceCatcherManager.Close()
                                                End Sub

        AddHandler Me.VisibleChanged, Sub(sender As Object, evt As EventArgs)
                                          Me.NotifyIcon1.Visible = Not Me.Visible
                                      End Sub
    End Sub

    Private Sub tsmiNewTask_Click(sender As System.Object, e As System.EventArgs) Handles tsmiNewTask.Click
        Dim _Dlg As New DlgNewTask()
        If _Dlg.ShowDialog() = DialogResult.OK Then
            Dim _ResTaskInfo As ResTaskInfo = _Dlg.ResTaskInfo
            WebResourceCatcherManager.Add(Me, _ResTaskInfo)
        End If
    End Sub


    Private Sub FrmMainBase_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        WebResourceCatcherManager.Close()
        System.Environment.Exit(System.Environment.ExitCode)
    End Sub

    Private Sub tsmiToTaskBar_Click(sender As System.Object, e As System.EventArgs) Handles tsmiToTaskBar.Click
        Me.Hide()
    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        Me.Show()
    End Sub

    Private Sub tsmiShow_Click(sender As System.Object, e As System.EventArgs) Handles tsmiShow.Click
        Me.Show()
    End Sub

    Private Sub tsmiRestart_Click(sender As System.Object, e As System.EventArgs) Handles tsmiRestart.Click
        Application.Restart()
    End Sub

    Private Sub tsmiExit_Click(sender As System.Object, e As System.EventArgs) Handles tsmiExit.Click
        Me.Close()
    End Sub

    Private Sub tsmiInput_Click(sender As System.Object, e As System.EventArgs) Handles tsmiInput.Click
        'Dim _FilePath As String = String.Empty
        'Using _OpenFileDialog As New OpenFileDialog()
        '    If _OpenFileDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then
        '        _FilePath = _OpenFileDialog.FileName

        '        'WebResourceCatcherManager.DomainUrl = WebResourceCatcherManager.GetDomainFormFileName(_FilePath)

        '        'Dim _Result As Boolean = Me.m_ResourceManager.Load(_FilePath)
        '        'If _Result = True Then
        '        '    Me.m_isPause = True
        '        '    Me.setButtonStatus(True, False, False, True)
        '        'End If
        '    End If
        'End Using
    End Sub

End Class